﻿@model Yes.Web.Blog.Models.IndexView
@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<div class="layoutMultiColumn-container">
    <div class="layoutMultiColumn layoutMultiColumn--primary">
        <div class="blockGroup homeGroup u-paddingTop50">

            @if (!string.IsNullOrEmpty(Model.Keyword))
            {
                Model.PageType = Yes.Domain.Enum.PageTypeEnum.Search;
                <div class="heading-title">搜索  “<b>@(Model.Keyword)</b>”</div>
            }
            else if (Model.CategoryId > 0)
            {
                Model.PageType = Yes.Domain.Enum.PageTypeEnum.Category;
                var cate = Model.CategoryList.FirstOrDefault(p => p.Id == Model.CategoryId) ?? new Yes.Domain.Entity.CategoryEntity { Name = "默认分类" };
                <div class="heading-title">分类  “<b>@(cate.Name)</b>”</div>
            }
            else if (Model.Year > 0 && Model.Month > 0)
            {
                Model.PageType = Yes.Domain.Enum.PageTypeEnum.Archive;
                <div class="heading-title">归档  <b>@(Model.Year)</b>年<b>@(Model.Month)</b>月</div>
            }
            else if (Model.Year > 0)
            {
                Model.PageType = Yes.Domain.Enum.PageTypeEnum.Archive;
                <div class="heading-title">归档  <b>@(Model.Year)</b>年</div>
            }
            else if (Model.TagId > 0)
            {
                Model.PageType = Yes.Domain.Enum.PageTypeEnum.Tag;
                var tag = Model.TagList.FirstOrDefault(p => p.Id == Model.TagId) ?? new Yes.Application.Article.Dto.TagDto { Name = "标签" };
                <div class="heading-title">标签  “<b>@(tag.Name)</b>”</div>
            }
            else
            {
                Model.PageType = Yes.Domain.Enum.PageTypeEnum.Index;
                <div class="heading-title">我的文章</div>

            }


            @foreach (var article in Model.PageInfo.List)
            {

                if (!string.IsNullOrEmpty(Model.Keyword))
                {
                    article.Title = article.Title.Replace(Model.Keyword, "<b>" + Model.Keyword + "</b>");
                }
                var cate = Model.CategoryList.FirstOrDefault(p => p.Id == article.CategoryId) ?? new Yes.Domain.Entity.CategoryEntity() { Name = "" };
                <article class="block--list block--withoutImage u-clearfix" itemscope="itemscope" itemtype="http://schema.org/Article">
                    @if (!string.IsNullOrEmpty(article.Img))
                    {
                        <a href="@(Url.Action("Detail", "Article", new {id = article.Id}))" target="_blank"><img style="max-width: 140px; max-height: 140px;border: 1px solid rgba(0,0,0,.05);float: right;margin: 2px 0 0 20px;" src="@(article.Img)" /></a>
                    }


                    <div class="block-content">
                        <h2 class="block-title" itemprop="headline" style="width:500px; overflow:hidden">
                            <a href="@(Url.Action("Detail", "Article", new {id = article.Id}))" target="_blank">@(Html.Raw(article.Title))</a>
                        </h2>
                        <div class="block-snippet" itemprop="about" style=" table-layout:fixed; word-break: break-all; ">@(Html.Raw(article.Summary))</div>
                        <div class="block-postMeta">
                            <a href="@(Url.Action("Category", "Article", new {CategoryId = cate.Id}))" rel="category tag">@(cate.Name)</a>

                            <span class="middotDivider"></span>
                            <a href="@(Url.Action("Archive", "Article", new {Year = article.PublishDate.Year, Month = article.PublishDate.Month}))">
                                <time itemprop="datePublished">@(article.PublishDate.ToString("yyyy-MM-dd"))</time>
                            </a>
                            <span class="middotDivider"></span>
                            评论(@(article.CommentCount))
                            <span class="middotDivider"></span>
                            阅读(@(article.ReadCount))
                        </div>
                    </div>
                </article>
            }
            @if (Model.PageInfo.Count == 0)
            {
                <p class="block-content u-paddingTop50 u-textAlignCenter">没有任何文章</p>
            }
        </div>
        @if (Model.PageInfo.PageCount > 1)
        {
            <div class="block-more u-textAlignRight u-marginRight20">
                @for (var page = 1; page <= Model.PageInfo.PageCount; page++)
                {
                    if (page == Model.PageInfo.PageIndex)
                    {
                        <span>@(page)</span>
                    }
                    else
                    {
                        switch (Model.PageType)
                        {
                            case Yes.Domain.Enum.PageTypeEnum.Index:
                                <a href="@(Url.Action("Index","Article",new { IndexPage = page }))">@(page)</a>
                                break;
                            case Yes.Domain.Enum.PageTypeEnum.Search:
                                <a href="@(Url.Action("Search","Article",new { SearchPage = page, keyword= Model.Keyword }))">@(page)</a>
                                break;
                            case Yes.Domain.Enum.PageTypeEnum.Category:
                                <a href="@(Url.Action("Category","Article",new { CategoryPage = page,Model.CategoryId  }))">@(page)</a>
                                break;

                            case Yes.Domain.Enum.PageTypeEnum.Archive:
                                <a href="@(Url.Action("Archive","Article",new { ArchivePage = page, Model.Year,Model.Month }))">@(page)</a>
                                break;

                            case Yes.Domain.Enum.PageTypeEnum.Tag:
                                <a href="@(Url.Action("Tag","Article",new { TagPage = page, Model.TagId }))">@(page)</a>
                                break;
                        }

                    }

                }
            </div>
        }

    </div>

    @Html.Partial("Right", Model)

</div>
